package tr.edu.boun.phys.springmassmodel.synth;

import tr.edu.boun.phys.springmassmodel.Mass;
import tr.edu.boun.phys.springmassmodel.Spring;
import tr.edu.boun.phys.springmassmodel.SpringMassModel;
import tr.edu.boun.phys.springmassmodel.Vector2D;

public class ScanStringModel extends ScannedSynth {

	@Override
	SpringMassModel createSpringMassModel() {
		int N = 128;
		Vector2D r = new Vector2D();
		Vector2D v = new Vector2D(0.0, 0.0);
		SpringMassModel stringModel = new SpringMassModel();
		for(int i=0; i<N; i++) {
			r.set(i*0.5-30, 0);
			//r.set(i*0.5-30, 5*Math.sin(2*Math.PI*i/(N-1)));
			r.set(i*0.5-30, 5-0.1*Math.abs(i-N/2));
			Mass m = new Mass(0.4, r, v);
			m.setB(0.00001);
			m.setConstraint(Mass.Y_ONLY);
			stringModel.addMass( m );
		}
		for(int i=0; i<N-1; i++) {
			Spring s = new Spring(stringModel.getMass(i), stringModel.getMass(i+1) );
			s.setK(0.002);
			s.setInitialLength( s.getInitialLength()/20000 );
			stringModel.addSpring(s);
		}
		
		stringModel.getMass(0).setConstraint( Mass.NO_FREEDOM );
		stringModel.getMass(N-1).setConstraint( Mass.NO_FREEDOM );
		return stringModel;
	}

	@Override
	public int[] getSamples() {
		int N = this.model.getNumberOfMasses()-1;
		int[] samples = new int[N];
		for(int i=0; i<N; i++) {
			double y0 = this.model.getMass(i).getInitialLocation().y;
			double y = this.model.getMass(i).getLocation().y;
			samples[i] = (int)(1000*y);			
		}
		return samples;
	}

}
